In this video we learn how to change a single column labels and a single index labels in a pen.
That's data frame.
And so far we only learned how to change and replace a complete row or column index.
And there are many cases and rewrote but we only want to change one or two entries in an index object
so let's import pandas here and we import our Summer Olympic Games medal data set and we said to the
athlete column to the index
and then we can select our index object here.
So here we have our labels of our row index and we can select a single entry.
So for example the first element in exposition 0 here it's off the tiles and let's assume now we are
not happy with the spelling of for the tiles.
So we think that there must be a Y instead of a J and we can try to set our new value here and we get
here an error message because an index object M is immutable the however there is a way to do this or
to change a single label or entry with the rename method so let's have a look at the renamed method
and press shift tab and in the rename method we have to pass a map bar and in the map we have to define
the old label that we want to rename and we have to define the new label.
And other methods would be actually a dictionary where on the left side is the key we have to define
the oth label that we want to replace.
And on the right side as well you of our dictionary we have to define the new value of the new label
that replaces and the old label and that's another parameter called Xs.
Where it we have to define which X is them on a map.
Also target
so in other words we have to define in which X is spend US should change here for the tiles.
And here in our example we have to define um the row axis and either we can pass a zero.
Let's check here.
Now we have our new spelling with the Y all we can say in quotation marks uh index.
So both alternatives are possible here and also here.
We get off the tiles and y and last but not least the less and the in-place perimeter which we have
to set to true if we want to change our data frame and set up the new value here.
So now let's check again our data frame.
And here we can see that we have changed our label three tiles.
So here we have now a Y.
And we can also do the same for a column label.
So for example we want to change the gender label to sex and we want to change the city label to host
city so we can change more than only one label so we can change many labels here and we can create a
map dictionary with many a key value Paris.
So here in this example to key value pairs so we have here our dictionary and on the left side is the
old label that we want to change gender and as a value the new labor and then be separated with a comma.
And then on the left side that's another key of our dictionary city.
So this is the label we want to change.
And on the right side as the value of our dictionary f our new label host city and again we have to
define the axis.
And in this case it is the column axis.
So one
so we can see where your host city and sex are not gender.
And instead of passing one to the parameter axis we can also pass columns
so we if you have a city and sex.
And again we have to separate the in-place parameter to true.
If you want to change our data frame and let's say again all that a frame and now we can see here.
So we changed our label for the tiles our index label and we changed our column labels host city and
sex.
All right.
So now this is it for the time being and hope to see you in the next session by.